package cn.rocky.pandacodegen.controller;

import cn.rocky.pandacodegen.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController extends BaseController{

    /**
        {
            "code":20000,
            "data": {
                "token":"admin-token"
            }
        }
    */
    @PostMapping("/login")
    @ResponseBody
    public R login() {
        log.info("ok");
        Map<Object, Object> map = new HashMap<>();
        map.put("token","admin-token");
        return new R().ok(R.CODE_VUE,map);
    }

    /**
        {
            "code": 20000,
            "data": {
                "roles": [
                    "admin"
                ],
                 "introduction": "I am a super administrator",
                "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                "name": "Super Admin"
            }
        }
     */
    @GetMapping("/info")
    public R info(@RequestParam("token") String token) {
        log.info("token: {}",token);
        Map<String, Object> map = new HashMap<>();
        map.put("roles", Collections.singletonList("admin"));
        map.put("introduction","I am a super administrator");
        map.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        map.put("name","Super Admin");
        return new R().ok(R.CODE_VUE, map);
    }
    /**
        {
            "code":20000,
            "data":"success"
        }
    */
    @PostMapping("/logout")
    @ResponseBody
    public R logout() {
        return new R().ok(R.CODE_VUE, "success");
    }
}
